#include "CUDAVolumeRenderer.h"
#include "Constants.h"
#include "DataLoader.h"
#include "CudaHelpers.h"
#include "RayMarch.h"

void CUDAVolumeRenderer::Render(Settings* settings)
{
	float* d;
	int sizeX = 0;
	int sizeY = 0;
	int sizeZ = 0;
	LoadData(settings->getInputFilename(), &d, sizeX, sizeY, sizeZ);
	settings->setDataSize(sizeX, sizeY, sizeZ);

	float* d_d = AllocateAndCopy(d, sizeX * sizeY * sizeZ);
	free(d);

	float3 direction = settings->getDirection();

	float* d_s = Allocate(settings->getImageWidth() * settings->getImageHeight() * 4);
	rayMarch(5000.f, direction, d_d, d_s, settings);

	SaveAsImage(settings->getOutputFilename(), d_s, settings->getImageWidth(), settings->getImageHeight(), .0f, settings->getOutputMultiplier());

	//SaveAsImage("test.bmp", d_d + (DATA_SIZEX * DATA_SIZEX) * 31, IMAGE_WIDTH, IMAGE_HEIGHT, .0f, .1f);

	Free(d_s);
	Free(d_d);
}
